package tpf.designer.pattern.course5.structure_pattern2.flyweight_13.authorization_2;

import org.apache.log4j.Logger;
import org.junit.Test;


public class Client {

    public static final Logger LOGGER = Logger.getLogger(Client.class);

    @Test
    public void testClient(){
        //需要先登录，然后再判断是否有权限
        SecurityMgr mgr = SecurityMgr.getInstance();
        mgr.login("张三");
        mgr.login("李四");
//        mgr.login("网无");
        boolean f1 = mgr.hasPermit("张三","薪资数据","查看");
        boolean f2 = mgr.hasPermit("李四","薪资数据","查看");
        boolean f3 = mgr.hasPermit("李四","薪资数据","修改");
//        boolean f4 = mgr.hasPermit("网无","薪资数据","修改");

        /*LOGGER.info("f1=="+f1);
        LOGGER.info("f2=="+f2);
        LOGGER.info("f3=="+f3);*/

        for(int i=0;i<3;i++){
            mgr.login("张三"+i);
            mgr.hasPermit("张三"+i,"薪资数据","查看");
        }

        //特别提醒：这里查看的引用次数，不是指测试使用的次数，指的是
        //SecurityMgr的queryByUser方法通过享元工厂去获取享元对象的次数
        LOGGER.info("薪资数据,查看 被引用了"+FlyweightFactory.getInstance().getUseTimes("薪资数据,查看")+"次");
        LOGGER.info("薪资数据,修改 被引用了"+FlyweightFactory.getInstance().getUseTimes("薪资数据,修改")+"次");
        LOGGER.info("人员列表,查看 被引用了"+FlyweightFactory.getInstance().getUseTimes("人员列表,查看")+"次");
    }
}
